var dispatcher = require("../../../util/dispatcher");

module.exports = function (app) {
	return new Handler(app);
};

var Handler = function (app) {
	this.app = app;
};

var handler = Handler.prototype;

handler.queryEntry = function (msg, session, next) {
	var connectors = this.app.getServersByType("connector");
	if (!connectors || connectors.length === 0) {
		next(null, {
			code: 500
		});

	} else {
		var timestamp = Date.parse(new Date());
		var res = dispatcher.dispatch(timestamp.toString(), connectors);
		next(null, {
			code: 200,
			host: res.host,
			port: res.clientPort
		});
	}
};
